/*
 * @Description:
 * @Author: zhaokun
 * @Date: 2022-01-27 08:46:11
 * @LastEditTime: 2022-01-27 15:36:18
 * @FilePath: \user\rpc\internal\logic\getcountlogic.go
 */
package logic

import (
	"context"

	"user/models"
	"user/rpc/internal/svc"
	"user/rpc/user"

	"github.com/tal-tech/go-zero/core/logx"
)

type GetCountLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGetCountLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetCountLogic {
	return &GetCountLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GetCountLogic) GetCount(in *user.CountRequest) (*user.CountResponse, error) {
	// todo: add your logic here and delete this line
	countResponse := &user.CountResponse{}
	userModel := &models.User{}
	paramSlice := make([]interface{}, len(in.Param))
	for i, val := range in.Param {
		paramSlice[i] = val
	}
	count, err := l.svcCtx.Model.Where(in.Where, paramSlice...).Count(userModel)
	countResponse.Count = int32(count)
	return countResponse, err
}
